import { makeAutoObservable, observable } from "mobx";
import type { LoginUserInfo } from "../permission/LoginUser";

/**
 * 默认值
 */
const defaultLoginUserInfo: LoginUserInfo = {
  user: {
    userId: 0,
    userName: "",   // 用户名
    nickName: "",   // 昵称
    userType: "",
    amount: 0,     // 算力点
    admin: false,
    email: "",
    phonenumber: "",
    sex: "",
    avatar: "",
    password: "",
    status: "",
    delFlag: "",
    loginIp: "",
    loginDate: "",
    createTime: "",
    updateTime: "",
  },
  roles: [],
  permissions: []
}


class GlobalStore{
  // 是否开启登录弹框
  isOpenLoginModal = false;

  // 用户是否已登录
  isUserLogined = false;

  // 登录用户信息
  loginUserInfo: LoginUserInfo = defaultLoginUserInfo;

  constructor(){
    makeAutoObservable(this,{
      loginUserInfo: observable.ref,
    })
  }
  
  /**
   * 设置用户是否登录
   */
  setUserLogined = (value: boolean) => this.isUserLogined = value;

  /**
   * 设置用户登录信息
   */
  setLoginUserInfo = (info: LoginUserInfo) => this.loginUserInfo = info;

  /**
   * 打开登录弹框
   */
  openLoginModal = () => this.isOpenLoginModal = true;

  /**
   * 关闭登录弹框
   */
  closeLoginModal = () => this.isOpenLoginModal = false;
}


export const globalStore = new GlobalStore();



